<?php
/**
 * TomatoCMS
 *
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 *
 * @copyright    Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license        http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version     $Id: list.phtml 3107 2010-05-30 14:28:09Z quanvo $
 */
?>
<?php
$this->headTitle($this->translator('product_list_page_title'));

$this->headLink()
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.core.css')
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.resizable.css')
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.dialog.css')
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.theme.css');

$this->headScript()
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.core.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.draggable.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.resizable.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.dialog.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.validate/jquery.validate.min.js');
?>

<div class="grid_12 t_a_ui_breadcrumb">
    <span><?php echo $this->translator('product_list_breadcump'); ?></span>
</div>

<div class="grid_12 t_a_bottom">
    <div class="grid_9 alpha"><?php echo $this->translator('product_list_guide'); ?></div>
    <div class="grid_3 omega">
        <div class="t_a_right">
            <a href="<?php echo $this->url(array(), 'shop_product_add'); ?>" class="t_a_ui_button_link"><span><?php echo $this->translator('product_add_breadcump'); ?></span></a>
        </div>
    </div>
</div>

<!-- Search form -->
<form method="POST" action="<?php echo $this->url(array(), 'shop_product_list'); ?>" id="frmProductSearch">
<div class="grid_12 t_a_bottom">
    <div class="prefix_1 suffix_1">
        <div class="clearfix t_a_bottom">
            <div class="grid_5 alpha">
                <label><?php echo $this->translator('product_list_search_category'); ?>:</label>
                <select name="category" style="width: 170px">
                    <option value="">---</option>
                    <?php for ($i = 0; $i < count($this->categories); $i++) : ?>
                    <option value="<?php echo $this->categories[$i]->category_id; ?>"<?php if (isset($this->exp['category_id']) && $this->exp['category_id'] == $this->categories[$i]->category_id) : ?> selected="selected"<?php endif; ?>><?php echo str_repeat('---', $this->categories[$i]->depth).$this->categories[$i]->category_admin_name; ?></option>
                    <?php endfor; ?>
                </select>
            </div>
        </div>

        <hr />

        <div class="clearfix t_a_bottom">
            <label>&nbsp;</label>
            <button type="submit"><span><?php echo $this->translator('product_list_search_button'); ?></span></button>
        </div>
    </div>
</div>
</form>
<!--end search form-->

<!-- Filter -->
<!--<div class="grid_12 t_a_bottom">
    <?php
    /**
    * Allows user to use status filters
    * @since 2.0.7
    */
    ?>
    <div class="t_a_right">
        <ul class="t_a_ui_filter">
            <li<?php if (!isset($this->exp['status'])) : ?> class="t_a_ui_active"<?php endif; ?>>
                <a href="<?php //echo $this->linkFilter($this->exp); ?>"><?php echo $this->translator('article_list_filter_all'); ?></a>
            </li>
            <li<?php if (isset($this->exp['status']) && $this->exp['status'] == 'active') : ?> class="t_a_ui_active"<?php endif; ?>>
                <a href="<?php //echo $this->linkFilter($this->exp, 'active'); ?>"><?php echo $this->translator('article_list_filter_activated'); ?></a>
            </li>
            <li<?php if (isset($this->exp['status']) && $this->exp['status'] == 'inactive') : ?> class="t_a_ui_active"<?php endif; ?>>
                <a href="<?php /*echo $this->linkFilter($this->exp, 'inactive');*/ ?>"><?php echo $this->translator('article_list_filter_not_activated'); ?></a>
            </li>
        </ul>
    </div>
</div>-->

<?php if ($this->numProduct == 0) : ?>
<div class="grid_12 t_a_bottom"><?php echo $this->translator('product_list_not_found'); ?></div>
<?php else : ?>
    <div class="grid_12 t_a_ui_data_list_header">
        <div class="grid_4 alpha">
            <div><input type="checkbox" id="checkAll" /> <?php echo $this->translator('product_main_title'); ?></div>
        </div>
        <div class="grid_5"><?php echo $this->translator('product_content_name'); ?></div>
        <div class="grid_2"><?php echo $this->translator('product_status'); ?></div>
        <div class="grid_1 omega"><?php echo $this->translator('product_id'); ?></div>
    </div>

    <div class="grid_12 t_a_bottom" id="articles">
        <?php foreach ($this->product as $row) : ?>
        <div id="tArticleRow_<?php echo $row->product_id; ?>" class="clearfix t_a_ui_data_list_content">

            <div class="grid_4 alpha">
                <div>
                    <input type="checkbox" class="selectProduct" value="<?php echo $row->product_id; ?>" />
                    <a href="<?php echo $this->url(array('product_id' => $row->product_id), 'shop_product_edit'); ?>"><?php echo $row->product_admin_name?></a>
                </div>

                <div class="t_a_top t_a_ui_helper_action">
                    <?php if ($this->allow('edit')) : ?>
                    <a href="<?php echo $this->url(array('product_id' => $row->product_id), 'shop_product_edit'); ?>"><?php echo $this->translator('product_list_action_edit'); ?></a>
                    <?php endif; ?>

                    <?php if ($this->allow('delete')) : ?>
                     | <a class="deleteAction" rel="<?php echo $row->product_id; ?>" href="javascript: void(0);"><?php echo $this->translator('product_list_action_delete'); ?></a>
                    <?php endif; ?>

                    <?php if ($this->allow('duplicate')) : ?>
                     | <a class="duplicateAction" rel="<?php echo $row->product_id; ?>" href="javascript: void(0);"><?php echo $this->translator('product_list_action_duplicate'); ?></a>
                    <?php endif; ?>
                </div>
            </div>
            <div class="grid_5">
                <?php echo ($this->arrPoductContentName[$row->product_id])?$this->arrPoductContentName[$row->product_id]:'-'; ?>
            </div>
            <div class="grid_2" id="tAricleStatus_<?php echo $row->product_id; ?>">
                <?php if($row->product_status == 1):?>
                <?php echo $this->translator('product_status_active'); ?>
                <?php else:?>
                <font color="Red"><?php echo $this->translator('product_status_inactive'); ?></font>
                <?php endif;?>
            </div>
            <div class="grid_1 omega"><?php echo $row->product_id;?></div>
        </div>
        <?php endforeach; ?>
    </div>

    <div class="grid_12 t_a_bottom t_a_paginator">
        <?php //echo $this->paginator()->slide($this->paginator, $this->paginatorOptions); ?>
    </div>
<?php endif; ?>

<div id="tDialogContainer"></div>
<div id="tConfirmBox"></div>

<script type="text/javascript">
$(document).ready(function() {
    <?php if ($this->allow('delete')) : ?>
    $('a.tDeleteAction').click(function() {
        var self = this;
        $('#tConfirmBox').html('<?php echo addslashes($this->translator('product_list_action_delete_confirm')); ?>')
            .dialog({
                title: '<?php echo addslashes($this->translator('common_dialog_confirm')); ?>',
                closeOnEscape: false,
                resizable: false,
                modal: true,
                open: function(event, ui) {
                    $('.ui-dialog-titlebar-close').hide();
                },
                buttons: {
                    '<?php echo addslashes($this->translator('common_dialog_confirm_no')); ?>': function() {
                        $(this).dialog('destroy');
                    },
                    '<?php echo addslashes($this->translator('common_dialog_confirm_yes')); ?>': function() {
                        $(this).dialog('destroy');
                        $(self).html('').addClass('t_a_loading');
                        var id = $(self).attr('rel');
                        $.ajaxq('news_article', {
                            type: 'POST',
                            url: "<?php echo $this->url(array(), 'shop_product_delete'); ?>",
                            data: { id: id },
                            success: function(response) {
                                if ('RESULT_OK' == response) {
                                    $('#tArticleRow_' + id).fadeOut('slow');
                                }
                            }
                        });
                    }
                }
            });
    });
    <?php endif; ?>

    <?php if ($this->allow('duplicate')) : ?>
    $('a.tDuplicateAction').click(function() {
        var self = this;
        $('#tConfirmBox').html('<?php echo addslashes($this->translator('product_list_action_duplicate_confirm')); ?>')
            .dialog({
                title: '<?php echo addslashes($this->translator('common_dialog_confirm')); ?>',
                closeOnEscape: false,
                resizable: false,
                modal: true,
                open: function(event, ui) {
                    $('.ui-dialog-titlebar-close').hide();
                },
                buttons: {
                    '<?php echo addslashes($this->translator('common_dialog_confirm_no')); ?>': function() {
                        $(this).dialog('destroy');
                    },
                    '<?php echo addslashes($this->translator('common_dialog_confirm_yes')); ?>': function() {
                        $(this).dialog('destroy');
                        $(self).html('').addClass('t_a_loading');
                        var id = $(self).attr('rel');
                        $.ajaxq('news_article', {
                            type: 'POST',
                            url: "<?php echo $this->url(array(), 'shop_product_duplicate'); ?>",
                            data: { product_id: id },
                            success: function(response) {
                                if ('RESULT_OK' == response) {
                                    var href = 'http://'+'<?php echo $_SERVER['HTTP_HOST']?>'+'<?php echo $_SERVER['SCRIPT_NAME']?>'+'/admin/shop/product/list';
                                    window.location = href;
                                }
                            }
                        });
                    }
                }
            });
    });
    <?php endif; ?>
});
</script>
